package org.linlinjava.litemall.admin.service2;

import org.linlinjava.litemall.core.util.R;
import org.linlinjava.litemall.db.dao.TAdMapper;
import org.linlinjava.litemall.db.dao.TNoticeMapper;
import org.linlinjava.litemall.db.domain.TAd;
import org.linlinjava.litemall.db.domain.TAdExample;
import org.linlinjava.litemall.db.domain.TNotice;
import org.linlinjava.litemall.db.domain.TNoticeExample;
import org.linlinjava.litemall.db.util.Str;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * 广告管理
 */
@Service
public class AdManagerService {


    @Autowired
    private TAdMapper adMapper;
    @Autowired
    private TNoticeMapper noticeMapper;

    /**
     * 广告列表
     *
     * @return
     */
    public Object adList() {
        return adMapper.selectByExample(new TAdExample());
    }


    public Object updateImg(TAd _ad) {
        TAd ad = adMapper.selectByPrimaryKey(_ad.getId());
        ad.setImg(_ad.getImg());
        ad.setEnable(_ad.getEnable());
        adMapper.updateByPrimaryKey(ad);
        return true;
    }


    /**
     * 通告列表
     *
     * @return
     */
    public Object noticeList() {
        return noticeMapper.selectByExample(new TNoticeExample());
    }

    /**
     * 增加通告
     *
     * @param notice
     * @return
     */
    public boolean addNotice(TNotice notice) {
        notice.setCreatedTime(LocalDateTime.now());
        noticeMapper.insert(notice);
        return true;
    }

    public boolean delNotice(TNotice notice) {
        noticeMapper.deleteByPrimaryKey(notice.getId());
        return true;
    }
}
